package com.rlz.net

/**
 * Created by RLZ
 * on 2021/5/13
 *
 * 网络请求的 配置方式  针对每一次请求
 */
class NetParams {
    /**
     * 在线缓存时间，不设置就是不用
     */
    private var mOnlineCacheTime = 0


    /**
     * 离线缓存时间，不设置就是不用
     */
    private var mOfflineCacheTime = 0


    /**
     * 重连次数 大于0 开启重连
     * 默认不重连
     */
    private var mRetryCount = 0


    /**
     * 同一网络，oneTag只能用一次
     */
    private var mOneTag: String? = null


    /**
     * 是否显示 loading
     */
    private var mIsShowDialog = true


    /**
     * loading 上的提示文案
     */
    private var mLoadingMessage: String? = ""


    companion object {
        @JvmStatic
        fun build(): NetParams {
            return NetParams()
        }
    }

    fun loading(loadingMessage: String?): NetParams {
        mLoadingMessage = loadingMessage
        return this
    }

    fun dialog(isShowDialog: Boolean): NetParams {
        mIsShowDialog = isShowDialog
        return this
    }

    fun oneTag(oneTag: String?): NetParams {
        mOneTag = oneTag
        return this
    }

    fun retry(retryCount: Int): NetParams {
        mRetryCount = retryCount
        return this
    }

    fun offlineCacheTime(offlineCacheTime: Int): NetParams {
        mOfflineCacheTime = offlineCacheTime
        return this
    }

    fun onlineCacheTime(onlineCacheTime: Int): NetParams {
        mOnlineCacheTime = onlineCacheTime
        return this
    }

    fun getOnlineCacheTime(): Int {
        return mOnlineCacheTime
    }

    fun getOfflineCacheTime(): Int {
        return mOfflineCacheTime
    }

    fun getRetryCount(): Int {
        return mRetryCount
    }

    fun getOneTag(): String? {
        return if (mOneTag == null) "" else mOneTag
    }

    fun dialog(): Boolean {
        return mIsShowDialog
    }

    fun getLoadingMessage(): String? {
        return if (mLoadingMessage == null) "" else mLoadingMessage
    }
}